package com.gexiaobao.pigeon.app.util

import android.graphics.Bitmap
import com.gexiaobao.pigeon.app.App.Companion.instance

/**
 * @Author      : hxw
 * @Date        : 2024/6/28 15:02
 * @Describe    :
 */
object ConstantsUtil {

    val IMG_FOLDER_PATH = instance.getExternalFilesDir(null)!!.path

    // Resize a Bitmap to fit within the specified max size
    fun smallImage(bitmap: Bitmap, maxSize: Int): Bitmap {
        val width = bitmap.width
        val height = bitmap.height
        val aspectRatio = width.toFloat() / height.toFloat()

        // Determine new dimensions while preserving aspect ratio
        val newWidth: Int
        val newHeight: Int
        if (width > height) {
            newWidth = maxSize
            newHeight = (newWidth / aspectRatio).toInt()
        } else {
            newHeight = maxSize
            newWidth = (newHeight * aspectRatio).toInt()
        }

        // Return resized Bitmap
        return Bitmap.createScaledBitmap(bitmap, newWidth, newHeight, false)
    }

}